﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;
using System.ComponentModel;
using ViewMaker.Core.Utils;

namespace ViewMaker.Core.Wpf
{
    public class WpfContentControlView : IViewContent
    {
        public ContentControl ContentControl
        {
            get { return content; }
        }
        private ContentControl content;

        public object Content
        {
            get { return content; }
        }

        public WpfContentControlView(ViewLayoutItem rootItem, object viewModel, ContentControl content = null)
        {
            this.content = content ?? new ContentControl();
            this.content.IsTabStop = false;
            this.content.DataContext = viewModel;

            ViewCommandBehavior.SetHelper(this.content, ServiceLocator.GetService<IViewCommandHelper>());

            var winSettigs = rootItem.Element.WindowSettings;
            if (winSettigs.FontSize.HasValue) this.content.FontSize = winSettigs.FontSize.Value;
            if (!string.IsNullOrEmpty(winSettigs.Foreground)) this.content.Foreground = (Brush)TypeDescriptor.GetConverter(typeof(Brush)).ConvertFromString(winSettigs.Foreground);
            if (!string.IsNullOrEmpty(winSettigs.Background)) this.content.Background = (Brush)TypeDescriptor.GetConverter(typeof(Brush)).ConvertFromString(winSettigs.Background);

        }
    }

}
